/**
 * 
 */
package org.vsg.stock.core.business;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.vsg.common.biz.exception.ServiceException;
import org.vsg.stock.core.domain.StockDailyKLine;
import org.vsg.stock.core.persistence.StockDailyKLineDao;

/**
 * @author Bill Vison
 *
 */
public class StockDailyKLineBO {
	
	private String stockCode;
	
	@Resource
	private StockDailyKLineDao stockDailyKLineDao;
	
	@Resource
	private StoppingTradeDaysBO stoppingTradeDaysBO;
	
	
	public String getStockCode() {
		return stockCode;
	}

	public void setStockCode(String stockCode) {
		this.stockCode = stockCode;
	}

	public List<StockDailyKLine> findStockLineByCycle(Date recentDate, int cycle) throws ServiceException {
		
		Calendar tmpCale = Calendar.getInstance();
		tmpCale.setTime(recentDate);
		
		int i = cycle;
		
		while ( i > 0) {
			// --- change object ---
			tmpCale.add(Calendar.DATE, -1);
			if (!stoppingTradeDaysBO.isTradingDate(tmpCale) ) {
				continue;
			}
			i = i -1;
			
		}
		Date startDate = tmpCale.getTime();
		
		List<StockDailyKLine> listKLines = stockDailyKLineDao.findStockLineByCycle(this.stockCode, startDate, recentDate);
		return listKLines;
	}
	
}
